﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CommonProperties.cs" company="Sander van Vliet">
//   2011 Sander van Vliet
// </copyright>
// <summary>
//   The common properties.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace TFDP.Common
{
    using System.ComponentModel;
    using System.Runtime.InteropServices;

    using Microsoft.VisualStudio.Data.Schema.Package.Project;

    /// <summary>
    /// The common properties.
    /// </summary>
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class CommonProperties : IExtenderType
    {
        #region Constants and Fields

        /// <summary>
        ///   The add to parent.
        /// </summary>
        public const string AddToParent = "AddToParent";

        /// <summary>
        ///   The is generated property.
        /// </summary>
        public const string IsGeneratedProperty = "IsGenerated";

        /// <summary>
        ///   The overwrite always.
        /// </summary>
        public const string OverwriteAlways = "OverwriteAlways";

        /// <summary>
        ///   The parent.
        /// </summary>
        public const string Parent = "Parent";

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets Node.
        /// </summary>
        [Browsable(false)]
        public IDatabaseNode Node { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// The get property value.
        /// </summary>
        /// <param name="propertyName">
        /// The property name. 
        /// </param>
        /// <returns>
        /// The property value. 
        /// </returns>
        protected string GetPropertyValue(string propertyName)
        {
            string returnValue = string.Empty;

            if (this.Node == null)
            {
                return returnValue;
            }

            this.Node.GetItemAttribute(propertyName, out returnValue);

            return returnValue;
        }

        /// <summary>
        /// The set property value.
        /// </summary>
        /// <param name="propertyName">
        /// The property name. 
        /// </param>
        /// <param name="value">
        /// The value. 
        /// </param>
        protected void SetPropertyValue(string propertyName, string value)
        {
            if (this.Node == null)
            {
                return;
            }

            this.Node.SetItemAttribute(propertyName, value);
        }

        #endregion
    }
}